home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * cantext -
- * Draw points, lines, rectangles and texture maps onto a
- * canvas.
- *
- * Paul Haeberli - 1991
- *
- * exports
- *
- void drawtext(c,fnt,mat,xpos,ypos,string)
- *
- */
- #include "stdio.h"
- #include "math.h"
- #include "canvas.h"
- #include "objfnt.h"
- #include "polyscan.h"
-
- static void transpoint(mat2d *mat,double ix,double iy,double *ox,double *oy)
- {
- *ox = mat->a*ix+mat->b*iy+mat->tx;
- *oy = mat->c*ix+mat->d*iy+mat->ty;
- }
-
- static void printmat2(mat2d *mat)
- {
- fprintf(stderr,"a %f\n",mat->a);
- fprintf(stderr,"b %f\n",mat->b);
- fprintf(stderr,"c %f\n",mat->c);
- fprintf(stderr,"d %f\n",mat->d);
- fprintf(stderr,"tx ty %f %f\n",mat->tx,mat->ty);
- }
-
- static void candrawchar(sptr,mat,cxpos,cypos)
- short *sptr;
- mat2d *mat;
- float cxpos, cypos;
- {
- int nverts;
- double tx, ty;
-
- while(1) {
- switch(*sptr++) {
- case PO_BGNLOOP:
- cannextfacet();
- break;
- case PO_ENDBGNLOOP:
- cannextfacet();
- break;
- case PO_RETENDLOOP:
- cannextfacet();
- return;
- break;
- case PO_RET:
- return;
- break;
- }
- nverts = *sptr++;
- while(nverts--) {
- transpoint(mat,(double)sptr[0],(double)sptr[1],&tx,&ty);
- canvertex(cxpos+tx,cypos+ty);
- sptr+=2;
- }
- }
- }
-
- void drawtext(c,fnt,mat,xpos,ypos,text,supersample)
- canvas *c;
- objfnt *fnt;
- mat2d *mat;
- float *xpos, *ypos;
- char *text;
- {
- chardesc *cd;
- int ixpos, iypos;
- double dx, dy, cxpos, cypos;
-
- ixpos = 0;
- iypos = 0;
- dx = 0.0;
- dy = 0.0;
- while(*text) {
- cd = getchardesc(fnt,*text);
- if(cd && cd->data) {
- cxpos = *xpos+dx;
- cypos = *ypos+dy;
- canbeginscan(c,supersample);
- candrawchar(cd->data,mat,cxpos,cypos);
- canendscan();
- ixpos += cd->movex;
- iypos += cd->movey;
- transpoint(mat,(double)ixpos,(double)iypos,&dx,&dy);
- }
- text++;
- }
- *xpos = *xpos+dx;
- *ypos = *ypos+dy;
- }
-